# -*- coding: utf-8 -*-
# @Time : 2022-01-06 11:27
# @Author : Z
# @Function :
from selenium.webdriver.common.by import By

from Common.Logger import path
from Keywords.web_keys import Web

web = Web()
web.open_browser()

# 登陆
web.get_url('http://testingedu.com.cn:8000/index.php/Home/user/login.html')
web.input('//input[@id="username"]', '13800138006')
web.input('//*[@id="password"]', '123456')
# web.get_verify('//*[@id="verify_code_img"]')
web.free_verify('//*[@id="verify_code_img"]')
web.input('//*[@id="verify_code"]', '{verify}')
web.click('//*[@name="sbtbutton"]')
web.sleep('6')

# 修改个人信息
# web.get_url('http://testingedu.com.cn:8000/index.php/Home/User/info.html')
# 点击头像
# web.click('//*[@id="preview"]')
# 进入iframe
# web.into_iframe('//*[@id="layui-layer-iframe1"]')
# web.input('//*[@id="filePicker"]/div[2]/input','test.png')
# 点击选择图片
# web.click('//*[@id="filePicker"]/div[2]/label')
# web.upload_image('test.png')
# web.sleep('1')
# web.click_js('//div[@class="saveBtn"]')
# web.sleep('1')
# web.out_iframe()
# web.click_js('//*[@id="woman"]')

# # 新增收货地址
# web.get_url('http://testingedu.com.cn:8000/index.php/Home/User/address_list.html')
# web.click_js('//*[text()="增加新地址"]')
# web.input('//*[@name="consignee"]', 'will测试')
# web.input('//*[@name="mobile"]', '0755-86140485')
# web.select('//*[@id="province"]', '北京市')
# web.select('//*[@id="city"]', '市辖区')
# web.select('//*[@id="district"]', '东城区')
# web.select('//*[@id="twon"]', '东华门街道')
# web.input('//*[@name="address"]', '收货地址')
# web.input('//*[@name="zipcode"]', '537300')
# web.click_js('//*[@id="address_submit"]')

# # 删除地址
# # web.click_js('//span[text()="will测试"]/../..//li[4]/a[2]')
# # web.sleep('1')

# 搜索商品
web.get_url('http://testingedu.com.cn:8000/index.php/Home/User/index.html')
web.input('//*[@name="q"]', '手机')
web.click_js('//*[text()="搜索"]')

# # 获取所有商品
# # goods = web.driver.find_elements(By.XPATH,'//div[@class="shop-list-splb p"]//div[@class="shop_name2"]/a')
# # print(type(goods))
# # for good in goods:
# #     print(good.text)

# 下单
web.click_js('//*[contains(text(),"鲜花礼盒花束速递")]')
# for i in range(2):
#     web.click_js('//*[@class="add"]')
# web.input('//*[@id="number"]', '4')
web.click_js('//*[@id="join_cart"]')
web.sleep('2')
web.click_js('//span[@class="layui-layer-setwin"]/a')
web.hover('//span[text()="我的购物车"]')
web.click_js('//a[@class="c-btn"]')

# 结算
web.click_js('//a[@class="paytotal"]')
web.click_js('//*[@class="checkout-submit"]')
web.get_text('//p[@class="succ-p"]', '：  (.+?) ')
web.get_text('//p[@class="succ-p"]', r'\d{18}',"orderid")
web.save_param('new_orderid', '{orderid}')
print(web.relations)

# 删除订单
web.click_js('//*[text()="我的订单"]')
web.switch_win()
web.sleep('1')
web.click_js('//*[text()="{new_orderid}"]/../..//a[text()="取消订单"]')
web.sleep('1')
web.click_js('//*[text()="确定"]')
web.sleep('1')
web.click_js('//*[text()="确定"]')

# web.assertMysql("SELECT * from userinfo where username='will';", "username", "will")
# web.quit()
